package org.datacoder.geocoding.datastructures.geoshapes

/**
 * A GeoShape representing an interval.  Intervals can be
 * either horizontal or vertical.
 */
abstract class GeoInterval extends GeoShape {

    public abstract double retrieveSingleValue(){}
    public abstract double retrieveMinDoubleValue(){}
    public abstract double retrieveMaxDoubleValue(){}

    public boolean containsInterval(double min, double max){
        if((retrieveMinDoubleValue() <= min) && (max <= retrieveMaxDoubleValue())){
            return true
        }
        return false
    }
    public boolean containsPoint(double point){
        if((retrieveMinDoubleValue() <= point) && (point <= retrieveMaxDoubleValue())){
            return true
        }
        return false
    }
    public boolean intersectsInterval(double min, double max){
        if(containsPoint(min) ||
            ((min <= retrieveMinDoubleValue()) && (retrieveMinDoubleValue() <= max))){
            return true
        }
        return false
    }
    public boolean intersectsPerpendicularInterval(GeoInterval gi){
        if(
            (retrieveMinDoubleValue() <= gi.retrieveSingleValue()) &&
            (gi.retrieveSingleValue() <= retrieveMaxDoubleValue()) &&
            (gi.retrieveMinDoubleValue() <= retrieveSingleValue()) &&
            (retrieveSingleValue() <= gi.retrieveMaxDoubleValue())
        ){
            return true
        }
        return false
    }

    public double retrieveCenter(){
        return (retrieveMinDoubleValue() + retrieveMaxDoubleValue())/2
    }

}

